home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH19 / SHMAPP2.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-07-17  |  3.3 KB  |  127 lines

  1. ; SHMAPP2.ASM
  2. ;
  3. ; This is a shared memory application that uses the static shared memory
  4. ; TSR (SHARDMEM.ASM).  This program assumes the user has already run the
  5. ; SHMAPP1 program to insert a string into shared memory.  This program
  6. ; simply prints that string from shared memory.
  7. ;
  8.         .xlist
  9.         include     stdlib.a
  10.         includelib    stdlib.lib
  11.         .list
  12.  
  13. dseg        segment    para public 'data'
  14. ShmID        byte    0
  15. dseg        ends
  16.  
  17. cseg        segment    para public 'code'
  18.         assume    cs:cseg, ds:dseg, es:SharedMemory
  19.  
  20. ; SeeIfPresent-    Checks to see if the shared memory TSR is present in memory.
  21. ;        Sets the zero flag if it is, clears the zero flag if
  22. ;        it is not.  This routine also returns the TSR ID in CL.
  23.  
  24. SeeIfPresent    proc    near
  25.         push    es
  26.         push    ds
  27.         push    di
  28.         mov    cx, 0ffh        ;Start with ID 0FFh.
  29. IDLoop:        mov    ah, cl
  30.         push    cx
  31.         mov    al, 0            ;Verify presence call.
  32.         int    2Fh
  33.         pop    cx
  34.         cmp    al, 0            ;Present in memory?
  35.         je    TryNext
  36.         strcmpl
  37.         byte    "Static Shared Memory TSR",0
  38.         je    Success
  39.  
  40. TryNext:    dec    cl            ;Test USER IDs of 80h..FFh
  41.         js    IDLoop
  42.         cmp    cx, 0            ;Clear zero flag.
  43. Success:    pop    di
  44.         pop    ds
  45.         pop    es
  46.         ret
  47. SeeIfPresent    endp
  48.  
  49.  
  50.  
  51. ; The main program for application #1 links with the shared memory
  52. ; TSR and then reads a string from the user (storing the string into
  53. ; shared memory) and then terminates.
  54.  
  55. Main        proc
  56.         assume    cs:cseg, ds:dseg, es:SharedMemory
  57.         mov    ax, dseg
  58.         mov    ds, ax
  59.         meminit
  60.  
  61.         print
  62.         byte    "Shared memory application #2",cr,lf,0
  63.  
  64. ; See if the shared memory TSR is around:
  65.  
  66.         call    SeeIfPresent
  67.         je    ItsThere
  68.         print
  69.         byte    "Shared Memory TSR (SHARDMEM) is not loaded.",cr,lf
  70.         byte    "This program cannot continue execution.",cr,lf,0
  71.         ExitPgm
  72.  
  73. ; If the shared memory TSR is present, get the address of the shared segment
  74. ; into the ES register:
  75.  
  76. ItsThere:    mov    ah, cl        ;ID of our TSR.
  77.         mov    al, 10h        ;Get shared segment address.
  78.         int    2Fh
  79.  
  80. ; Print the string input in SHMAPP1:
  81.  
  82.         print
  83.         byte    "String from SHMAPP1 is '",0
  84.  
  85.         lea    di, InputLine    ;ES already points at proper seg.
  86.         puts
  87.  
  88.         print
  89.         byte    "' from shared memory.",cr,lf,0
  90.  
  91.  
  92. Quit:        ExitPgm            ;DOS macro to quit program.
  93. Main        endp
  94.  
  95. cseg            ends
  96.  
  97. sseg        segment    para stack 'stack'
  98. stk        db    1024 dup ("stack   ")
  99. sseg        ends
  100.  
  101. zzzzzzseg    segment    para public 'zzzzzz'
  102. LastBytes    db    16 dup (?)
  103. zzzzzzseg    ends
  104.  
  105.  
  106. ; The shared memory segment must appear after "zzzzzzseg".
  107. ; Note that this isn't the physical storage for the data in the
  108. ; shared segment.  It's really just a place holder so we can declare
  109. ; variables and generate their offsets appropriately.  The UCR Standard
  110. ; Library will reuse the memory associated with this segment for the
  111. ; heap.  To access data in the shared segment, this application calls
  112. ; the shared memory TSR to obtain the true segment address of the
  113. ; shared memory segment.  It can then access variables in the shared
  114. ; memory segment (where ever it happens to be) off the ES register.
  115. ;
  116. ; Note that all the variable declarations go into an include file.
  117. ; All applications that refer to the shared memory segment include
  118. ; this file in the SharedMemory segment.  This ensures that all
  119. ; shared segments have the exact same variable layout.
  120.  
  121. SharedMemory    segment    para public 'Shared'
  122.  
  123.         include    shmvars.asm
  124.  
  125. SharedMemory    ends
  126.         end    Main
  127.